package com.tupu.controller.permission;


import com.tupu.common.Result;
import com.tupu.entity.permission.PermissionInfo;
import com.tupu.service.permission.PermissionListService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@CrossOrigin
@RestController
@RequestMapping("/api/permission")
public class PermissionController {

    @Autowired(required = false)
    private PermissionListService permissionListService;

    /**
     * 所有权限列表
     *
     * @return
     */
    @PostMapping("/list")
    public Result<List<PermissionInfo>> list() {
        try {
            List<PermissionInfo> all = permissionListService.findAll();
            return Result.ok(all);
        } catch (Exception e) {
            return Result.errorMessage(e.getMessage());
        }
    }

    /**
     * 通过权限id 查询一条数据
     *
     * @param permission_id
     * @return
     */
    @PostMapping("/findById")
    public Result<PermissionInfo> findById(@RequestParam(required = false) Integer permission_id) {
        try {
            PermissionInfo one = permissionListService.getById(permission_id);
            return Result.ok(one);
        } catch (Exception e) {
            return Result.errorMessage(e.getMessage());
        }
    }

}